package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.ComponentParameter;
import com.zoo.diannaopeijian.mapper.ComponentParameterMapper;
import com.zoo.diannaopeijian.service.ComponentParameterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配件参数服务实现类
 */
@Service
public class ComponentParameterServiceImpl implements ComponentParameterService {
    @Resource
    private ComponentParameterMapper componentParameterMapper;

    @Override
    public boolean addComponentParameter(ComponentParameter componentParameter) {
        if (CheckUtil.allNullBeanCheck(componentParameter)) {
            return true;
        }
        return componentParameterMapper.insertSelective(componentParameter) == 1;
    }

    @Override
    public boolean updateComponentParameter(ComponentParameter componentParameter) {
        if (CheckUtil.allNullBeanCheck(componentParameter)) {
            return true;
        }
        return componentParameterMapper.updateByPrimaryKeySelective(componentParameter) == 1;
    }

    @Override
    public boolean deleteComponentParameterById(Integer componentParameterId) {
        if (componentParameterId == null) {
            throw new NullPointerException();
        }
        return componentParameterMapper.deleteByPrimaryKey(componentParameterId) == 1;
    }

    @Override
    public List<ComponentParameter> getComponentParameter(ComponentParameter componentParameter) {
        return componentParameterMapper.select(componentParameter);
    }

    @Override
    public List<ComponentParameter> getComponentParameterWithPage(ComponentParameter componentParameter, Page page) {
        if (page != null) {
            page.onPage();
        }
        return getComponentParameter(componentParameter);
    }
}
